package br.com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import br.com.bean.ObservacaoBean;

public class ObservacaoDao {

public void inserir (Connection conn, ObservacaoBean value) throws Exception{
		
		String sql = "INSERT INTO obeservacao(descricao) VALUES (?)";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, value.getDescricao());
		ps.execute();
		ps.close();
		
	}
	
	public void alterar (Connection conn, ObservacaoBean value) throws Exception{
		
		String sql = "UPDATE obeservacao SET descricao=? WHERE id = ?;";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, value.getDescricao());
		ps.execute();
		ps.close();

	}
	
	public void excluir (Connection conn, ObservacaoBean value) throws Exception {

		String sql = "DELETE * FROM obeservacao WHERE id = ?;";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, value.getId());
		ps.executeUpdate();
	}
	
	public ArrayList<ObservacaoBean> getLista(Connection conn, ObservacaoBean value) throws Exception{

		String sql = "SELECT descricao FROM obeservacao where id = ?;";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, value.getId());
		ResultSet rs = ps.executeQuery();
		ArrayList<ObservacaoBean> na = new ArrayList<ObservacaoBean>();
		while(rs.next()){
			ObservacaoBean a = new ObservacaoBean();
			a.setDescricao(rs.getString("descricao"));
			na.add(a);
		}
		return na;
	}

	public ArrayList<ObservacaoBean> getLista(Connection conn) throws Exception{

		String sql = "SELECT descricao FROM obeservacao;";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		ArrayList<ObservacaoBean> na = new ArrayList<ObservacaoBean>();
		while(rs.next()){
			ObservacaoBean a = new ObservacaoBean();
			a.setDescricao(rs.getString("descricao"));
			na.add(a);
		}
		return na;
	}	
}
